import Vue from 'vue';
import Vuex from 'vuex';
// vuex的持久化插件
import persistedstate from "vuex-persistedstate";
Vue.use(Vuex)

export default new Vuex.Store({
    state: {
        userInfo:null,
        softeem_ele_client_token:null,
        actionSheetConfig:{
            isShow:false,
            menuList:[],
            callBack:null
        }
    },
    mutations: {
        setUserInfo(state,userInfo){
            state.userInfo = userInfo;
        },
        set_softeem_ele_client_token(state,softeem_ele_client_token){
            state.softeem_ele_client_token = softeem_ele_client_token;
        },
        logOut(state){
            state.userInfo = null;
            state.softeem_ele_client_token = null;
        },
        setActionSheetConfig(state,config){
            state.actionSheetConfig = config;
        }
    },
    actions: {
        setUserInfo({commit},userInfo){
            commit("setUserInfo",userInfo);
        },
        set_softeem_ele_client_token({commit},softeem_ele_client_token){
            commit("set_softeem_ele_client_token",softeem_ele_client_token);
        },
        logOut({commit}){
            commit("logOut");
        },
        showActionSheet({commit},config){
            config.isShow = true;
            commit("setActionSheetConfig",config);
        },
        hideActionSheet({commit}){
            let config = {
                isShow:false,
                menuList: [],
                callBack: null
            }
            commit("setActionSheetConfig",config);
        }
    },
    // getters是从缓冲里取值的，所以需要加载持久化插件需要使用getters
    getters: {
        userInfo(state){
            return state.userInfo;
        },
        actionSheetConfig(state){
          return state.actionSheetConfig;
        }
    },
    plugins:[
        persistedstate({
            storage:window.sessionStorage
        })
    ]
})

